﻿// <copyright file="Menu.cs" company="ThorIndustry">Copyright (c) ThorIndustry. All rights reserved.</copyright>

using System.Collections.Generic;

public class Menu : UnityEngine.MonoBehaviour
{
    public UnityEngine.GameObject ButtonPrefab;
    public UnityEngine.GameObject HomePrefab;
    public UnityEngine.GameObject ExitPrefab;
    protected List<Button> buttons = new List<Button>();

    public IGuiController GuiController
    {
        get;
        set;
    }

    public bool IsVisible
    {
        get;
        private set;
    }

    public virtual void Hide()
    {
        UnityEngine.Debug.Log("Menu hide : " + this.GetType().ToString());

        for (int index = 0; index < this.buttons.Count; ++index)
        {
            this.buttons[index].IsVisible = false;
            this.buttons[index].gameObject.SetActive(false);
        }

        this.IsVisible = false;
    }

    public virtual void Initialize(IGuiController guiController)
    {
        this.GuiController = guiController;
    }

    public virtual void Show(params object[] parameters)
    {
        UnityEngine.Debug.Log("Menu show : " + this.GetType().ToString());

        for (int index = 0; index < this.buttons.Count; ++index)
        {
            this.buttons[index].IsVisible = true;
            this.buttons[index].gameObject.SetActive(true);
        }

        this.IsVisible = true;
    }

    protected virtual void Update()
    {
        if (this.IsVisible)
        {       
            // Check for back.
            if (UnityEngine.Input.GetKeyUp(UnityEngine.KeyCode.Escape))
            {
                this.GuiController.BackMenu();
                return;
            }
        }
    }
}
